package com.cmcc.aregister.ui.activity;

import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;

import com.cmcc.aregister.R;
import com.cmcc.aregister.cs.asntask.InterfaceUtils.DataCallback_get_other_orders;
import com.cmcc.aregister.cs.asntask.InterfaceUtils.DataCallback_other;
import com.cmcc.aregister.cs.asntask.MyAsynaTask;
import com.cmcc.aregister.cs.constant.Arguments;
import com.cmcc.aregister.cs.constant.ConfigUtilHelper;
import com.cmcc.aregister.cs.constant.GlobalSetting;
import com.cmcc.aregister.cs.constant.HelpInc;
import com.cmcc.aregister.cs.http.HttpAsyncTask;
import com.cmcc.aregister.cs.model.Appointment;
import com.cmcc.aregister.cs.model.AreaResultModel;
import com.cmcc.aregister.cs.model.DepResultModel;
import com.cmcc.aregister.cs.model.DocInfoModel;
import com.cmcc.aregister.cs.model.DocResultModel;
import com.cmcc.aregister.cs.model.FamilyModel;
import com.cmcc.aregister.cs.model.HospitalInfoModel;
import com.cmcc.aregister.cs.model.HospitalResultModel;
import com.cmcc.aregister.cs.model.MemberModel;
import com.cmcc.aregister.cs.model.OrderListResultModel;
import com.cmcc.aregister.cs.model.OrderModel;
import com.cmcc.aregister.cs.model.PayTypeModel;
import com.cmcc.aregister.cs.model.QuickYuyueEntity;
import com.cmcc.aregister.cs.model.Schedule;
import com.cmcc.aregister.cs.model.ScheduleResultModel;
import com.cmcc.aregister.cs.util.PotoalParcelable;
import com.cmcc.aregister.cs.util.Utils;
import com.cmcc.aregister.ui.adapter.LocalOrderInfoAdapter;
import com.cmcc.aregister.ui.adapter.OtherOrderInfoAdapter;
import com.cmcc.aregister.ui.dialog.QuickYuyueDlg;
import com.cmcc.aregister.ui.dialog.QuickYuyueMemberDlg;
import com.cmcc.aregister.ui.dialog.QuickYuyueTimeDlg;
import com.cmcc.sdk.CmccDataStatistics;
import com.oauth.utils.EncryptUtils;

/**
 * 订单管理，订单列表
 * 
 * @author ld
 * 
 */
public class AppManagerActivity extends ParentActivity implements HelpInc,
    DataCallback_get_other_orders
{
    private static final String TAG = "AppManagerActivity";
    // ------view------
    private Button top_right_btn;
    private ListView local_list;
    private ListView other_list;

    // ------parameter------
    private List<Appointment> localAppList = new ArrayList<Appointment>();
    private List<OrderModel> otherAppList = new ArrayList<OrderModel>();
    private LocalOrderInfoAdapter localAppAdapter;
    private OtherOrderInfoAdapter otherAppAdapter;

    private TabHost tabHost;

    MyAsynaTask asnTask;
    int currpage_other = 1;
    boolean isLocal = true;
    private boolean isOther = false;
    private List<MemberModel> members;

    private PopupWindow popupWindow;
    private int screenWidth;
    private int screenHeight;

    @SuppressLint("HandlerLeak")
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        init(R.layout.p_app_manager);

    }

    @Override
    protected void setupData()
    {
        isLocal = getIntent().getBooleanExtra("isLocal", true);
    }

    @Override
    protected void setupView()
    {
        ((ImageView) findViewById(R.id.title))
            .setBackgroundResource(R.drawable.my_app);
        top_right_btn = (Button) findViewById(R.id.top_right_btn);
        local_list = (ListView) findViewById(R.id.local_list);
        other_list = (ListView) findViewById(R.id.other_list);

        top_right_btn.setVisibility(View.GONE);
        top_right_btn.setText(R.string.fast_appointment);
        top_right_btn.setOnClickListener(onClickListener);
        local_list.setOnItemClickListener(localOnItemClickListener);
        other_list.setOnItemClickListener(otherOnItemClickListener);
        tabHost = (TabHost) findViewById(R.id.tabhost);
        tabHost.setup();

        LinearLayout tab1 = (LinearLayout) LayoutInflater.from(this).inflate(
            R.layout.tab_layout, null);

        LinearLayout tab2 = (LinearLayout) LayoutInflater.from(this).inflate(
            R.layout.tab_layout_two, null);

        tabHost.addTab(tabHost.newTabSpec("tab01").setIndicator(tab1)
            .setContent(R.id.tab_local_layout));

        tabHost.addTab(tabHost.newTabSpec("tab02").setIndicator(tab2)
            .setContent(R.id.tab_other_layout));

        tabHost.setOnTabChangedListener(mOnTabChanedL);
        if (isLocal)
        {
            // sendGetOrderInfoTask();
            tabHost.setCurrentTab(0);
        }
        else
        {
            // showProgressDialogNew(R.string.dialog_loading_other_order);
            // getOtherOrderList(currpage_other,
            // ConfigUtilHelper.getMobile(app));
            tabHost.setCurrentTab(1);
        }
    }

    OnTabChangeListener mOnTabChanedL = new OnTabChangeListener() {

        @Override
        public void onTabChanged(String tabId)
        {
            // TODO Auto-generated method stub
            if (tabId.equals("tab01"))
            {// 本地列表
                if (localAppList == null || localAppList.size() <= 0)
                {
                    sendGetOrderInfoTask();
                }
            }
            if (tabId.equals("tab02"))
            {// 异地列表
                if (otherAppList == null || otherAppList.size() <= 0)
                {
                    showProgressDialogNew(R.string.dialog_loading_other_order);
                    getOtherOrderList(currpage_other,
                        ConfigUtilHelper.getMobile(app));
                }
            }
        }
    };

    OnClickListener onClickListener = new OnClickListener() {
        @Override
        public void onClick(View v)
        {
            int id = v.getId();
            switch (id)
            {
            case R.id.top_right_btn:
                if (!Utils.isLogin(context))
                {
                    Intent intent_1 = new Intent(AppManagerActivity.this,
                        UserLoginActivity.class);
                    intent_1.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(intent_1);
                }
                else
                {
                    Intent intent_1 = new Intent(AppManagerActivity.this,
                        OrderDetailActivity.class);
                    intent_1.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(intent_1);
                }
                break;
            }
        }
    };

    Handler h;

    @Override
    protected void onResume()
    {
        super.onResume();
        if (isLocal)
        {
            if (localAppList != null && localAppList.size() > 0)
            {
                if (localAppAdapter == null)
                {
                    localAppAdapter = new LocalOrderInfoAdapter(context,
                        localAppList, this);
                    local_list.setAdapter(localAppAdapter);
                }
                else
                {
                    localAppAdapter.notifyDataSetChanged();
                }
            }
            else
            {
                sendGetOrderInfoTask();
                tabHost.setCurrentTab(0);
            }
        }

        if (app.cancelAppFlag)
        {
            if (app.area_type == 0)
            {
                if (app.appPosition != -1)
                {
                    localAppList.get(app.appPosition).yuyue_state = "-1";
                    localAppAdapter.list = localAppList;
                    local_list.setAdapter(localAppAdapter);
                }
            }
            else
            {
                otherAppList.get(app.appPosition).orderStatus = "4";
                // otherAppAdapter.list = otherAppList;
                otherAppAdapter.notifyDataSetChanged();
                // other_list.setAdapter(otherAppAdapter);
            }
            app.cancelAppFlag = false;
            app.appPosition = -1;
            app.area_type = -1;
        }
    }

    @Override
    protected void onDestroy()
    {
        // TODO Auto-generated method stub
        super.onDestroy();
        app.cancelAppFlag = false;
        can_show_dlg = false;
        if (sendQuickHandler != null)
        {
            sendQuickHandler.removeCallbacks(sendQuickAppointmentTask);
            sendQuickHandler = null;
            can_show_mast = false;
        }
        if (sendGetScheduleListTaskHandler != null)
        {
            sendGetScheduleListTaskHandler
                .removeCallbacks(sendGetScheduleListTask);
            sendGetScheduleListTaskHandler = null;
            can_show_sch = false;
        }
    }

    QuickYuyueEntity quick;
    QuickYuyueDlg dlg_mast;
    QuickYuyueTimeDlg dlg_sch;
    QuickYuyueMemberDlg dlg_member;
    private boolean can_show_mast = true;
    private boolean can_show_sch = true;
    private boolean can_show_dlg = true;
    /**
     * 再次预约请求处理结果handler
     */
    Handler sendQuickHandler = new Handler() {
        public void handleMessage(Message msg)
        {
            logger.d("----------sendCancelOtherOrderHandler----------");
            switch (msg.what)
            {
            case HttpAsyncTask.TASK_NOTIFY_RETURN_DATA:
                dismissProgressDialog();
                if (msg.obj != null)
                {
                    Map<String, Object> httpMap = (Map<String, Object>) msg.obj;
                    String status = (String) httpMap.get(Arguments.XML_STATUS);
                    String message = (String) httpMap
                        .get(Arguments.XML_MESSAGE);
                    quick = (QuickYuyueEntity) httpMap
                        .get(Arguments.XML_QUICK_DATA);
                    if ("0".equals(status))
                    {
                        app.cancelApp(0, position);
                        if (can_show_mast)
                        {
                            dlg_mast = new QuickYuyueDlg(
                                AppManagerActivity.this, quick.mMastEntity,
                                AppManagerActivity.this);
                            dlg_mast.show();
                        }
                    }
                    else
                    {
                        showSingleAlertDlg(getString(R.string.notice), message,
                            getString(R.string.close));
                    }
                }
                else
                {
                    showSingleAlertDlg(getString(R.string.notice),
                        getString(R.string.get_data_err),
                        getString(R.string.close));
                }
                break;
            case HttpAsyncTask.TASK_NOTIFY_CONNECTION_FAIL:
                dismissProgressDialog();
                showSingleAlertDlg(getString(R.string.notice),
                    getString(R.string.read_fail), getString(R.string.close));
                break;
            }
        }
    };

    /**
     * 快速预约
     */
    private HttpAsyncTask sendQuickAppointmentTask;

    private void sendQuickAppointmentTask(Appointment mAppointment)
    {
        Map<String, String> parameterMap = new HashMap<String, String>();
        parameterMap.put("mobile", ConfigUtilHelper.getMobile(app));
        parameterMap.put("unit_name", mAppointment.unit_name);
        parameterMap.put("dep_name", mAppointment.dep_name);
        parameterMap.put("doctor_name", mAppointment.doctor_name);
        parameterMap.put("unit_id", mAppointment.unit_id);
        parameterMap.put("dep_id", mAppointment.dep_id);
        parameterMap.put("doctor_id", mAppointment.doctor_id);
        parameterMap.put("phone", mAppointment.phone);
        parameterMap.put("truename", mAppointment.truename);
        parameterMap.put("clinic_no", mAppointment.clinic_no);
        parameterMap.put("zcname", mAppointment.zcname);
        String getQuickUrl = Utils.changeUrl(Arguments.SERVER_URL_QUICK_YUYUE,
            parameterMap);
        if (ConfigUtilHelper.debug)
        {
            Log.i(TAG, "快速预约url：" + getQuickUrl);
        }
        sendQuickAppointmentTask = new HttpAsyncTask(HttpAsyncTask.GET,
            GlobalSetting.XML_QUICK_ORDER, getQuickUrl,
            HttpAsyncTask.CACHE_TYPE_ACTION, true);
        sendQuickAppointmentTask.setUIHandler(sendQuickHandler);
        showProgressDialog();
        mHttpManager.execute(sendQuickAppointmentTask);
    }

    Appointment appointment;
    /**
     * 本地列表点击进入详情
     */
    OnClickListener localOnClickListener = new OnClickListener() {
        @Override
        public void onClick(View v)
        {

            // getAgainOrder(app);
        }
    };
    /**
     * 本地列表点击进入详情
     */
    OnItemClickListener localOnItemClickListener = new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adapterview, View view, int i,
            long l)
        {
            appointment = localAppList.get(i);
            Intent intent = new Intent(AppManagerActivity.this,
                AppDetailActivity.class);
            Map<String, Object> httpMap = new HashMap<String, Object>();
            PotoalParcelable potoal = new PotoalParcelable(httpMap);
            httpMap.put(Arguments.ACTIVITY_JUMP_TYPE, 0);
            httpMap.put(Arguments.ACTIVITY_JUMP_NAME, appointment.truename);
            httpMap.put(Arguments.ACTIVITY_JUMP_CHN_NAME, appointment.chn_name);
            httpMap
                .put(Arguments.ACTIVITY_JUMP_HOSPITAL, appointment.unit_name);
            httpMap.put(Arguments.ACTIVITY_JUMP_UNIT_ID, appointment.unit_id);
            httpMap.put(Arguments.ACTIVITY_JUMP_DEPARTMENT,
                appointment.dep_name);
            httpMap
                .put(Arguments.ACTIVITY_JUMP_DOCTOR, appointment.doctor_name);
            httpMap.put(Arguments.ACTIVITY_JUMP_CHOICE_TIME,
                appointment.to_date);
            httpMap.put(Arguments.ACTIVITY_JUMP_CHOICE_TIME_BEGIN,
                appointment.begin_time);
            httpMap.put(Arguments.ACTIVITY_JUMP_CHOICE_TIME_END,
                appointment.end_time);
            httpMap
                .put(Arguments.ACTIVITY_JUMP_STATUS, appointment.yuyue_state);
            httpMap.put(Arguments.ACTIVITY_JUMP_DETL_ID, appointment.yuyue_id);
            httpMap.put(Arguments.ACTIVITY_JUMP_ORDER_NO, appointment.order_no);
            httpMap.put(Arguments.ACTIVITY_JUMP_GUAHAO_AMT,
                appointment.guahao_amt);
            httpMap.put(Arguments.ACTIVITY_JUMP_POSITION, position);
            intent.putExtra(Arguments.INTENT_TO_NEXT_PAGE, potoal);

            httpMap.put(Arguments.ACTIVITY_JUMP_APP, appointment);

            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(intent);
        }

    };

    /**
     * 异地列表点击进入详情
     */
    OnItemClickListener otherOnItemClickListener = new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adapterview, View view, int i,
            long l)
        {
            OrderModel orderModel = otherAppList.get(i);
            try
            {
                String[] order_info = orderModel.orderDesc.split(" ");
                Intent intent = new Intent(AppManagerActivity.this,
                    AppDetailActivity.class);
                Map<String, Object> httpMap = new HashMap<String, Object>();
                PotoalParcelable potoal = new PotoalParcelable(httpMap);
                httpMap.put(Arguments.ACTIVITY_JUMP_TYPE, 1);
                httpMap.put(Arguments.ACTIVITY_JUMP_HOSPITAL, order_info[2]);
                httpMap.put(Arguments.ACTIVITY_JUMP_DEPARTMENT, order_info[3]);
                httpMap.put(Arguments.ACTIVITY_JUMP_DOCTOR, order_info[4]);
                if (order_info.length >= 7)
                {
                    httpMap.put(Arguments.ACTIVITY_JUMP_CHOICE_TIME,
                        order_info[5] + " " + order_info[6] + " "
                            + order_info[7]);
                }
                httpMap.put(Arguments.ACTIVITY_JUMP_STATUS,
                    orderModel.orderStatus);
                httpMap
                    .put(Arguments.ACTIVITY_JUMP_DETL_ID, orderModel.orderNo);
                httpMap.put(Arguments.ACTIVITY_JUMP_POSITION, i);
                httpMap.put(Arguments.ACTIVITY_JUMP_PAY_STATUS,
                    orderModel.payStatus);
                httpMap.put(Arguments.ACTIVITY_JUMP_USER_NAME,
                    orderModel.userName);
                httpMap.put(Arguments.ACTIVITY_JUMP_USER_MOBILE,
                    orderModel.mobile);
                httpMap.put(Arguments.ACTIVITY_JUMP_OTHER_ORDER_TIME,
                    orderModel.orderTime);
                httpMap.put(Arguments.ACTIVITY_JUMP_OTHER_ORDER_FEE,
                    orderModel.orderFee);
                httpMap.put(Arguments.ACTIVITY_JUMP_RESERVATION_TYPE,
                    orderModel.reservationType);
                httpMap.put(Arguments.ACTIVITY_JUMP_SERVICE_SUM_PRICE,
                    orderModel.serviceSumPrice);

                intent.putExtra(Arguments.INTENT_TO_NEXT_PAGE, potoal);
                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(intent);
            }
            catch (Exception e)
            {

            }
        }
    };

    /*
     * OnClickListener otherOnClickListener = new OnClickListener() {
     * 
     * @Override public void onClick(View v) { int position = (Integer)
     * v.getTag(R.id.tag_second); OrderModel orderModel =
     * otherAppList.get(position);
     * 
     * try { String[] order_info = orderModel.orderDesc.split(" "); Intent
     * intent = new Intent(AppManagerActivity.this, AppDetailActivity.class);
     * Map<String, Object> httpMap = new HashMap<String, Object>();
     * PotoalParcelable potoal = new PotoalParcelable(httpMap);
     * httpMap.put(Arguments.ACTIVITY_JUMP_TYPE, 1);
     * httpMap.put(Arguments.ACTIVITY_JUMP_HOSPITAL, order_info[2]);
     * httpMap.put(Arguments.ACTIVITY_JUMP_DEPARTMENT, order_info[3]);
     * httpMap.put(Arguments.ACTIVITY_JUMP_DOCTOR, order_info[4]);
     * httpMap.put(Arguments.ACTIVITY_JUMP_CHOICE_TIME,
     * orderModel.bestContactTime); httpMap.put(Arguments.ACTIVITY_JUMP_STATUS,
     * orderModel.orderStatus); httpMap.put(Arguments.ACTIVITY_JUMP_DETL_ID,
     * orderModel.orderNo); httpMap.put(Arguments.ACTIVITY_JUMP_POSITION,
     * position); httpMap.put(Arguments.ACTIVITY_JUMP_PAY_STATUS,
     * orderModel.payStatus); httpMap.put(Arguments.ACTIVITY_JUMP_USER_NAME,
     * orderModel.userName); httpMap.put(Arguments.ACTIVITY_JUMP_USER_MOBILE,
     * orderModel.mobile); httpMap.put(Arguments.ACTIVITY_JUMP_OTHER_ORDER_TIME,
     * orderModel.orderTime);
     * 
     * intent.putExtra(Arguments.INTENT_TO_NEXT_PAGE, potoal);
     * intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); }
     * catch (Exception e) {
     * 
     * } } };
     */

    public void setView(int type)
    {
        if (type == 0)
        {
            if (localAppList != null && localAppList.size() > 0)
            {
                localAppAdapter = new LocalOrderInfoAdapter(context,
                    localAppList, this);
                local_list.setAdapter(localAppAdapter);
                if (ConfigUtilHelper.debug)
                {
                    Log.i(TAG, "localAppList:" + localAppList.size());
                }
            }
        }
        else
        {

            // if (otherAppList != null && otherAppList.size() > 0) {
            // otherAppAdapter = new OtherOrderInfoAdapter(context,
            // otherAppList); other_list.setAdapter(otherAppAdapter); }

        }
    }

    /**
     * 获取用户订单信息
     */
    private HttpAsyncTask sendGetOrderInfoTask;

    private void sendGetOrderInfoTask()
    {
        logger.d("----------sendGetOrderInfoTask----------");
        Map<String, String> parameterMap = new HashMap<String, String>();
        parameterMap.put("mobile", ConfigUtilHelper.getMobile(app));
        String changeUserInfoUrl = Utils.changeUrl(
            Arguments.SERVER_URL_CHECK_ORDER_INFO, parameterMap);
        if (ConfigUtilHelper.debug)
        {
            Log.i(TAG, "changeUserInfoUrl:" + changeUserInfoUrl);
        }
        sendGetOrderInfoTask = new HttpAsyncTask(HttpAsyncTask.GET,
            GlobalSetting.XML_GET_ORDER_INFO, changeUserInfoUrl,
            HttpAsyncTask.CACHE_TYPE_ACTION, true);
        showProgressDialogNew(R.string.dialog_loading_local_order);
        sendGetOrderInfoTask.setUIHandler(sendGetOrderInfoTaskHandler);
        mHttpManager.execute(sendGetOrderInfoTask);
    }

    @SuppressWarnings("unchecked")
    Handler sendGetOrderInfoTaskHandler = new Handler() {
        public void handleMessage(Message msg)
        {
            logger.d("----------sendGetOrderInfoTaskHandler----------");
            switch (msg.what)
            {
            case HttpAsyncTask.TASK_NOTIFY_RETURN_DATA:
                dismissProgressDialog();
                if (msg.obj != null)
                {
                    Map<String, Object> httpMap = (Map<String, Object>) msg.obj;
                    localAppList = (List<Appointment>) httpMap
                        .get(Arguments.XML_ORDER_LIST);

                    setView(0);
                }
                break;
            case HttpAsyncTask.TASK_NOTIFY_CONNECTION_FAIL:
                dismissProgressDialog();
                showSingleAlertDlg(getString(R.string.notice),
                    getString(R.string.read_fail), getString(R.string.close));
                break;
            }
        }
    };

    /**
     * 初始化参数
     * 
     * @param parameterMap
     * @return
     */
    private Map<String, String> initArgMap(Map<String, String> parameterMap)
    {
        parameterMap.put("userId", Arguments.userId);
        parameterMap.put("timestamp", ConfigUtilHelper.getStringNow());
        parameterMap.put("userPwd", ConfigUtilHelper.getUserPwd());
        return parameterMap;
    }

    /**
     * 获取异地订单信息
     * 
     */
    private void getOtherOrderList(int page, String mobile)
    {
        Map<String, String> parameterMap = new HashMap<String, String>();
        parameterMap = initArgMap(parameterMap);
        parameterMap.put("methodVit", Arguments.GetOrders);
        parameterMap.put("mobile", mobile);
        parameterMap.put("reservationType", "");
        parameterMap.put("page", Integer.toString(page));
        parameterMap.put("pageSize", Arguments.pageSize);
        asnTask = new MyAsynaTask(this, GlobalSetting.XML_GET_OTHER_ORDERLIST,
            parameterMap);
        asnTask.execute();
    }

    /**
     * 异地就医订单查询
     */
    private HttpAsyncTask sendGetOtherOrderTask;

    /**
     * 
     * @param mobile 手机号码
     */
    private void sendGetOtherOrderTask()
    {
        Map<String, String> parameterMap = new HashMap<String, String>();
        parameterMap.put("mobile", ConfigUtilHelper.getMobile(app));
        String getOtherOrderUrl = Utils.changeUrl(
            Arguments.SERVER_URL_GET_OTHER_ORDER, parameterMap);
        sendGetOtherOrderTask = new HttpAsyncTask(HttpAsyncTask.GET,
            GlobalSetting.XML_GET_OTHER_ORDER, getOtherOrderUrl,
            HttpAsyncTask.CACHE_TYPE_ACTION, true);
        sendGetOtherOrderTask.setUIHandler(sendGetOtherOrderTaskHandler);
        mHttpManager.execute(sendGetOtherOrderTask);
    }

    @SuppressWarnings("unchecked")
    Handler sendGetOtherOrderTaskHandler = new Handler() {
        public void handleMessage(Message msg)
        {
            logger.d("----------sendGetOtherOrderTaskHandler----------");
            switch (msg.what)
            {
            case HttpAsyncTask.TASK_NOTIFY_RETURN_DATA:
                if (msg.obj != null)
                {
                    Map<String, Object> httpMap = (Map<String, Object>) msg.obj;
                    otherAppList = (List<OrderModel>) httpMap
                        .get(Arguments.XML_OTHER_ORDER_LIST);
                    setView(1);
                }
                break;
            case HttpAsyncTask.TASK_NOTIFY_CONNECTION_FAIL:
                showSingleAlertDlg(getString(R.string.notice),
                    getString(R.string.read_fail), getString(R.string.close));
                break;
            }
        }
    };

    @Override
    protected void setTaskHandlerNull()
    {
        if (sendGetOrderInfoTask != null)
        {
            sendGetOrderInfoTask.setTaskBindingHandler(null);
        }
        if (sendGetOtherOrderTask != null)
        {
            sendGetOtherOrderTask.setTaskBindingHandler(null);
        }
    }

    private String orderno;
    private String yuyueid;

    @Override
    public void notifyUI(int msg, int p)
    {
        // TODO Auto-generated method stub
        position = p;
        switch (msg)
        {
        case GlobalSetting.CANCEL_ORDER:// 取消预约
            sendCancelAppointmentTask(ConfigUtilHelper.getMobile(this),
                localAppList.get(p).unit_id, localAppList.get(p).yuyue_id);
            break;
        case GlobalSetting.AGIAN_ORDER:// 再次预约
            // 儿童医院、遗传代谢科、生酮饮食科预约提醒 111是儿童医院的ID,3887表示遗传代谢科 6546代表生酮饮食科
            if (localAppList.get(p).unit_id.equals("111"))
            {
                if (localAppList.get(p).dep_id.equals("3887"))
                {
                    showAlertTipDlg(getString(R.string.notice),
                        getString(R.string.yichuan_tip),
                        getString(R.string.confirm), getString(R.string.cancel));
                }
                else if (localAppList.get(p).dep_id.equals("6546"))
                {
                    showAlertTipDlg(getString(R.string.notice),
                        getString(R.string.shengtong_tip),
                        getString(R.string.confirm), getString(R.string.cancel));
                }
                else
                {
                    sendQuickAppointmentTask(localAppList.get(position));
                }
            }
            else
            {
                sendQuickAppointmentTask(localAppList.get(position));
            }
            break;
        case GlobalSetting.PAY_AGAIN:// 再次支付
            getPayTypeTask(localAppList.get(p).unit_id);
            orderno = localAppList.get(p).order_no;
            yuyueid = localAppList.get(p).yuyue_id;
        default:
            break;
        }
    }

    public void showAlertTipDlg(String title, String msg, String posTitle,
        String nagativeTitle)
    {
        new AlertDialog.Builder(this)
            .setTitle(title)
            .setMessage(msg)
            .setIcon(android.R.drawable.ic_dialog_info)
            .setCancelable(true)
            .setPositiveButton(posTitle, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which)
                {
                    sendQuickAppointmentTask(localAppList.get(position));
                }
            })
            .setNegativeButton(nagativeTitle,
                new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which)
                    {

                    }
                }).create().show();
    }

    private void newButton(ArrayList<PayTypeModel> paytypes)
    {
        if (null != popupWindow)
        {
            popupWindow.dismiss();
            popupWindow = null;
            return;
        }
        else
        {
            int index = 0;

            View popupWindowView = getLayoutInflater().inflate(
                R.layout.paytype_popwindow, null, false);
            LinearLayout paytypelLinearLayout = (LinearLayout) popupWindowView
                .findViewById(R.id.paytype_btn);
            screenWidth = getWindowManager().getDefaultDisplay().getWidth();
            screenHeight = getWindowManager().getDefaultDisplay().getHeight();
            int h = (int) (screenHeight / 2.15);
            for (PayTypeModel type : paytypes)
            {
                Button codeBtn = new Button(this);
                setBtnAttribute(codeBtn, type.cfg_value, index);
                paytypelLinearLayout.addView(codeBtn);
                codeBtn.setTag(type.cfg_code);
                index++;
            }
            Button cancelBtn = new Button(this);
            cancelBtn.setText(R.string.logout_no);
            cancelBtn.setBackgroundResource(R.drawable.weibo_btn);
            // RelativeLayout.LayoutParams rlp = new
            // RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT,60);
            // cancelBtn.setLayoutParams(rlp);
            cancelBtn.setTextSize(18);
            cancelBtn.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v)
                {
                    popupWindowClose();
                }
            });
            paytypelLinearLayout.addView(cancelBtn);
            popupWindow = new PopupWindow(popupWindowView, screenWidth, h, true);
            popupWindow.setFocusable(true);
            popupWindow.setAnimationStyle(R.style.PopupAnimation);
            popupWindow.showAtLocation(findViewById(R.id.p_manager_parent),
                Gravity.BOTTOM, 0, 0);
            popupWindow.update();
        }
    }

    private void setBtnAttribute(Button codeBtn, String btnContent, int id)
    {
        codeBtn.setText(btnContent);
        codeBtn.setId(id);
        codeBtn.setBackgroundResource(R.drawable.weibo_btn);
        codeBtn.setTextSize(18);
        // RelativeLayout.LayoutParams rlp = new RelativeLayout.LayoutParams(
        // LayoutParams.WRAP_CONTENT,60);
        // codeBtn.setLayoutParams(rlp);
        codeBtn.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v)
            {
                // 再次支付
                String payType = (String) v.getTag();
                // 如果选择银联支付
                if ("21".equals(payType))
                {
                    checkIsBind();
                }
                else
                {
                    payAgainAsyncTask("8", "wxcityMobileClient", orderno,
                        yuyueid, payType);
                }
                popupWindowClose();
            }
        });
    }

    private String params = "";
    private HttpAsyncTask queryBindCardTask;

    private void checkIsBind()
    {
        params = "cid=8&token=wxcityMobileClient&mid="
            + ConfigUtilHelper.getMobile(app);
        queryBindCardTask = new HttpAsyncTask(HttpAsyncTask.POST,
            GlobalSetting.XML_GET_BINDCARD, Arguments.CHECK_BIND_URL, params,
            HttpAsyncTask.CACHE_TYPE_ACTION, true);
        showProgressDialogNew(R.string.check_bind_info_tips);
        queryBindCardTask.setUIHandler(queryBindCardTaskHandler);
        mHttpManager.execute(queryBindCardTask);
    }

    private Handler queryBindCardTaskHandler = new Handler() {
        public void handleMessage(Message msg)
        {
            switch (msg.what)
            {
            case HttpAsyncTask.TASK_NOTIFY_RETURN_DATA:
                dismissProgressDialog();
                if (msg.obj != null)
                {
                    Map<String, Object> map = (Map<String, Object>) msg.obj;
                    String status = (String) map.get(Arguments.XML_STATUS);
                    if (!status.equals("1"))
                    {
                        showAlertDlg(getString(R.string.notice),
                            getString(R.string.payagain_suer_msg),
                            getString(R.string.dialog_yes),
                            getString(R.string.pay_a_moment));
                    }
                    else
                    {
                        payAgainAsyncTask("8", "wxcityMobileClient", orderno,
                            yuyueid, "21");
                    }
                }
                else
                {
                    showMsg(R.string.read_member_fail);
                }
                break;
            case HttpAsyncTask.TASK_NOTIFY_CONNECTION_FAIL:
                dismissProgressDialog();
                showSingleAlertDlg(getString(R.string.notice),
                    getString(R.string.get_bind_info_err),
                    getString(R.string.close));
                break;
            }
        };
    };

    /**
     * 银联绑定支付
     * @param title
     * @param msg
     * @param posTitle
     * @param nagativeTitle
     */
    public void showAlertDlg(String title, String msg, String posTitle,
        String nagativeTitle)
    {
        new AlertDialog.Builder(this)
            .setTitle(title)
            .setMessage(msg)
            .setIcon(android.R.drawable.ic_dialog_info)
            .setCancelable(false)
            .setPositiveButton(posTitle, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which)
                {
                    addBankCardActivity();
                }
            })
            .setNegativeButton(nagativeTitle,
                new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which)
                    {

                    }
                }).create().show();
    }

    /**
     * 获取医院的支付方式(再次支付)
     */
    private HttpAsyncTask getPayTypeTask;

    /**
     * 根据医院的ID获取支付方式（再次支付）
     * 
     * @param unit_id
     */
    private void getPayTypeTask(String unit_id)
    {
        Map<String, String> parameterMap = new HashMap<String, String>();
        parameterMap.put("unit_id", unit_id);
        parameterMap.put("mobile", ConfigUtilHelper.getMobile(app));
        String changeUserInfoUrl = Utils.changeUrl(
            Arguments.SERVER_URL_GET_HOSPITAL_PAY_TYPE, parameterMap);
        getPayTypeTask = new HttpAsyncTask(HttpAsyncTask.GET,
            GlobalSetting.XML_GET_HOSPITAL_PAY_TYPE_INFO, changeUserInfoUrl,
            HttpAsyncTask.CACHE_TYPE_ACTION, false);
        showProgressDialogNew(R.string.get_pay_type_tips);
        getPayTypeTask.setUIHandler(getPayTypeTaskHandler);
        mHttpManager.execute(getPayTypeTask);
    }

    Handler getPayTypeTaskHandler = new Handler() {
        public void handleMessage(Message msg)
        {
            switch (msg.what)
            {
            case HttpAsyncTask.TASK_NOTIFY_RETURN_DATA:
                if (msg.obj != null)
                {
                    Map<String, Object> map = (Map<String, Object>) msg.obj;
                    ArrayList<PayTypeModel> paytypes = (ArrayList<PayTypeModel>) map
                        .get(Arguments.XML_PAYTYPE_LIST);
                    newButton(paytypes);
                    dismissProgressDialog();
                    isLocal = true;
                }
                else
                {
                    dismissProgressDialog();
                }
                break;
            case HttpAsyncTask.TASK_NOTIFY_CONNECTION_FAIL:
                dismissProgressDialog();
                showSingleAlertDlg(getString(R.string.notice),
                    getString(R.string.read_fail), getString(R.string.close));
                break;
            }
        };
    };

    /**
     * 点击再次预约的位置
     */
    private int position;

    /**
     * 取消本地预约订单
     */
    private HttpAsyncTask sendCancelAppointmentTask;

    /**
     * 再次支付
     */
    private HttpAsyncTask payAgainAsyncTask;

    private void payAgainAsyncTask(String cid, String token, String orderno,
        String yuyue_id, String pay_type)
    {
        String params = "cid=8&token=wxcityMobileClient&pay_method=" + pay_type
            + "&order_no=" + orderno + "&yuyueid=" + yuyue_id;
        payAgainAsyncTask = new HttpAsyncTask(HttpAsyncTask.POST,
            GlobalSetting.XML_GET_PAYAGAIN, Arguments.PAY_AGAIN_URL, params,
            HttpAsyncTask.CACHE_TYPE_ACTION, true);
        payAgainAsyncTask.setUIHandler(payAgainHandler);
        showProgressDialogNew(R.string.dialog_loading_pay_again);
        mHttpManager.execute(payAgainAsyncTask);
    }

    Handler payAgainHandler = new Handler() {
        public void handleMessage(Message msg)
        {
            logger.d("----------payAgainHandler----------");
            switch (msg.what)
            {
            case HttpAsyncTask.TASK_NOTIFY_RETURN_DATA:
                dismissProgressDialog();
                if (msg.obj != null)
                {
                    Map<String, Object> httpMap = (Map<String, Object>) msg.obj;
                    // String status = (String)
                    // httpMap.get(Arguments.XML_STATUS);
                    String message = (String) httpMap
                        .get(Arguments.XML_MESSAGE);
                    showSingleAlertDlg(getString(R.string.notice), message,
                        getString(R.string.close));
                }
                else
                {
                    showSingleAlertDlg(getString(R.string.notice),
                        getString(R.string.pay_again_fail),
                        getString(R.string.close));
                }
                break;
            case HttpAsyncTask.TASK_NOTIFY_CONNECTION_FAIL:
                dismissProgressDialog();
                showSingleAlertDlg(getString(R.string.notice),
                    getString(R.string.read_fail), getString(R.string.close));
                break;
            }
        }
    };

    // 关闭弹出层
    private void popupWindowClose()
    {
        popupWindow.dismiss();
        popupWindow = null;
    }

    /**
     * 
     * @param mobile 手机号码
     * @param unit_id 医院ID
     * @param yuyue_id 订单ID
     */
    private void sendCancelAppointmentTask(String mobile, String unit_id,
        String yuyue_id)
    {
        Map<String, String> parameterMap = new HashMap<String, String>();
        parameterMap.put("client_auth", "test");
        parameterMap.put("token", "123456");
        String str = "mobile=" + mobile + "&yuyue_id=" + yuyue_id + "&type="
            + 2 + "&unit_id=" + unit_id;
        String entryStr = "";
        try
        {
            entryStr = EncryptUtils.encode(str);
            entryStr = URLEncoder.encode(entryStr, "UTF-8");
        }
        catch (Exception e)
        {
            Log.i(TAG, "取消本地预约订单参数加密出现错误");
        }
        parameterMap.put("s", entryStr);
        String params = Utils.getParams(parameterMap);
        sendCancelAppointmentTask = new HttpAsyncTask(HttpAsyncTask.POST,
            GlobalSetting.XML_CANCEL_APPOINTMENT,
            Arguments.SERVER_URL_CANCEL_APPOINTMENT, params,
            HttpAsyncTask.CACHE_TYPE_ACTION, true);
        sendCancelAppointmentTask.setUIHandler(sendCancelHandler);
        showProgressDialogNew(R.string.dialog_loading_order_cancel);
        mHttpManager.execute(sendCancelAppointmentTask);
    }

    Handler sendCancelHandler = new Handler() {
        public void handleMessage(Message msg)
        {
            logger.d("----------sendCancelOtherOrderHandler----------");
            switch (msg.what)
            {
            case HttpAsyncTask.TASK_NOTIFY_RETURN_DATA:
                dismissProgressDialog();
                if (msg.obj != null)
                {
                    Map<String, Object> httpMap = (Map<String, Object>) msg.obj;
                    String status = (String) httpMap.get(Arguments.XML_STATUS);
                    String message = (String) httpMap
                        .get(Arguments.XML_MESSAGE);
                    if ("0".equals(status))
                    {
                        if (can_show_dlg)
                        {
                            _showInfoDialog(message,
                                new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog,
                                        int which)
                                    {

                                    }
                                });
                        }
                    }
                    else
                    {

                        showSingleAlertDlg(getString(R.string.notice), message,
                            getString(R.string.close));
                    }
                }
                else
                {
                    showSingleAlertDlg(getString(R.string.notice),
                        getString(R.string.cancel_order_fail),
                        getString(R.string.close));
                }
                break;
            case HttpAsyncTask.TASK_NOTIFY_CONNECTION_FAIL:
                dismissProgressDialog();
                showSingleAlertDlg(getString(R.string.notice),
                    getString(R.string.read_fail), getString(R.string.close));
                break;
            }
        }
    };

    public void doSomeWork()
    {
        if (ConfigUtilHelper.debug)
        {
            Log.i(TAG, "position:" + position);
        }
        app.cancelApp(0, position);// 只有本地
        localAppList.get(position).yuyue_state = "-1";
        localAppAdapter = new LocalOrderInfoAdapter(context, localAppList, this);
        // localAppAdapter.notifyDataSetChanged();
        // mHandler.post(updateThread);
        local_list.setAdapter(localAppAdapter);
    }

    /**
     * 请求出诊班次信息
     */
    @Override
    public void notifyUI(String msg)
    {
        // TODO Auto-generated method stub
        sendGetScheduleListTask(localAppList.get(position).unit_id, msg);
    }

    /**
     * 查询出诊班次的号源信息
     */
    private HttpAsyncTask sendGetScheduleListTask;

    /**
     * 
     * @param unit_id 医院ID
     * @param schedule_id 班次
     */
    private void sendGetScheduleListTask(String unit_id, String schedule_id)
    {
        logger.d("----------sendGetScheduleListTask----------");
        Map<String, String> parameterMap = new HashMap<String, String>();
        parameterMap.put("unit_id", unit_id);
        parameterMap.put("schedule_id", schedule_id);
        String getScheduleListUrl = Utils.changeUrl(
            Arguments.SERVER_URL_GET_SCHEDULE_LIST, parameterMap);
        if (ConfigUtilHelper.debug)
        {
            Log.i(TAG, "查询出诊班次地址：" + getScheduleListUrl);
        }
        sendGetScheduleListTask = new HttpAsyncTask(HttpAsyncTask.GET,
            GlobalSetting.XML_SCHEDULE_LIST, getScheduleListUrl,
            HttpAsyncTask.CACHE_TYPE_SAVE, false);
        sendGetScheduleListTask.setUIHandler(sendGetScheduleListTaskHandler);
        showProgressDialog();
        mHttpManager.execute(sendGetScheduleListTask);
    }

    private int allPage;
    private int currPage;
    private List<Schedule> scheduleList = new ArrayList<Schedule>();
    @SuppressWarnings("unchecked")
    Handler sendGetScheduleListTaskHandler = new Handler() {
        public void handleMessage(Message msg)
        {
            logger.d("----------sendGetScheduleListTaskHandler----------");
            switch (msg.what)
            {
            case HttpAsyncTask.TASK_NOTIFY_RETURN_DATA:
                dismissProgressDialog();
                if (msg.obj != null)
                {
                    try
                    {
                        Map<String, Object> httpMap = (Map<String, Object>) msg.obj;
                        List<Schedule> scheduleList_1 = (List<Schedule>) httpMap
                            .get(Arguments.XML_SCHEDULE_LIST);
                        scheduleList = scheduleList_1;
                        /*
                         * if (currPage == 1) { scheduleList = scheduleList_1; }
                         * else { scheduleList.addAll(scheduleList_1); }
                         */
                        if (dlg_mast != null && dlg_mast.isShowing())
                        {
                            dlg_mast.dismiss();
                        }
                        if (can_show_sch)
                        {
                            if (scheduleList != null && !scheduleList.isEmpty())
                            {
                                if (TextUtils
                                    .isEmpty(scheduleList.get(0).schedule_id))
                                {
                                    showSingleAlertDlg(
                                        getString(R.string.notice),
                                        getString(R.string.get_data_err),
                                        getString(R.string.close));
                                }
                                else
                                {
                                    dlg_sch = new QuickYuyueTimeDlg(
                                        AppManagerActivity.this, scheduleList,
                                        AppManagerActivity.this);
                                    dlg_sch.show();
                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        e.printStackTrace();
                        allPage = currPage;
                    }
                }
                break;
            case HttpAsyncTask.TASK_NOTIFY_CONNECTION_FAIL:
                dismissProgressDialog();
                showSingleAlertDlg(getString(R.string.notice),
                    getString(R.string.read_fail), getString(R.string.close));
                allPage = currPage;
                break;
            }
        }
    };

    private String[] content = { "", "", "", "" };

    @Override
    public void notifyUI(int position)
    {
        // getHospitalPayTypeTask(quick.unit_id);
        getFamily();
        // TODO Auto-generated method stub
        /*
         * Intent intent_1 = new Intent(AppManagerActivity.this,
         * OrderDetailActivity.class); Map<String, Object> httpMap = new
         * HashMap<String, Object>(); int currentTitleSelect = R.id.left_btn;
         * httpMap.put(Arguments.ACTIVITY_JUMP_AREA_TYPE, currentTitleSelect);
         * httpMap.put(Arguments.ACTIVITY_JUMP_UNIT_ID, quick.unit_id);
         * httpMap.put(Arguments.ACTIVITY_JUMP_DETL_ID,
         * scheduleList.get(position).detl_id); content[0] = quick.unit_name;
         * content[1] = quick.dep_name; content[2] = quick.doctor_name;
         * content[3] = scheduleList.get(position).begin_time + " - " +
         * scheduleList.get(position).end_time;
         * httpMap.put(Arguments.ACTIVITY_JUMP_ORDER_DETAIL, content);
         * httpMap.put
         * (Arguments.ACTIVITY_JUMP_GUAHAO_AMT,quick.mMastEntity.get(0
         * ).guahao_amt); PotoalParcelable potoal = new
         * PotoalParcelable(httpMap);
         * intent_1.putExtra(Arguments.INTENT_TO_NEXT_PAGE, potoal);
         * intent_1.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
         * startActivity(intent_1);
         */
        this.position = position;
    }

    private void getFamily()
    {
        showProgressDialog();
        String params = "cid=8&token=wxcityMobileClient&phone="
            + ConfigUtilHelper.getMobile(app);
        sendGetFamilyTask = new HttpAsyncTask(HttpAsyncTask.POST,
            GlobalSetting.XML_GET_FAMILY_INFO, Arguments.GET_FAMILY_INFO_URL,
            params, HttpAsyncTask.CACHE_TYPE_ACTION, true);
        sendGetFamilyTask.setUIHandler(sendGetFamilyTaskHandler);
        mHttpManager.execute(sendGetFamilyTask);
    }

    /** 获取家庭成员信息 */
    private HttpAsyncTask sendGetFamilyTask;

    private Handler sendGetFamilyTaskHandler = new Handler() {
        public void handleMessage(Message msg)
        {
            switch (msg.what)
            {
            case HttpAsyncTask.TASK_NOTIFY_RETURN_DATA:
                dismissProgressDialog();
                if (msg.obj != null)
                {
                    Map<String, Object> map = (Map<String, Object>) msg.obj;
                    FamilyModel family = (FamilyModel) map
                        .get(Arguments.XML_FAMILY_INFO);
                    if (family != null && family.members != null
                        && family.members.size() > 0)
                    {
                        members = family.members;
                    }
                    if (isOther)
                    {
                        if (dlg_mast != null && dlg_mast.isShowing())
                        {
                            dlg_mast.dismiss();
                        }
                        String order_free_other = "0";
                        String[] orderDescs = otherAppList.get(position).orderDesc
                            .split(" ");
                        String orderDesc = "";
                        for (int i = 0; i < orderDescs.length; i++)
                        {
                            if (i < 5)
                            {
                                if (orderDesc.equals(""))
                                {
                                    orderDesc = orderDescs[i];
                                }
                                else
                                {
                                    orderDesc = orderDesc + " " + orderDescs[i];
                                }

                            }
                        }
                        orderDesc = orderDesc + " " + other_content;
                        // String[] desc = orderDesc.split(" ");
                        Intent intent_1 = new Intent(AppManagerActivity.this,
                            OrderDetailActivity.class);
                        Map<String, Object> httpMap = new HashMap<String, Object>();
                        httpMap.put(Arguments.ACTIVITY_JUMP_AREA_TYPE,
                            R.id.right_btn);

                        httpMap.put(Arguments.ACTIVITY_JUMP_CHOICE_DOCTOR_TYPE,
                            otherAppList.get(position).reservationType);
                        httpMap.put(Arguments.ACTIVITY_JUMP_DEP_ID,
                            otherAppList.get(position).deptId);
                        httpMap.put(Arguments.ACTIVITY_JUMP_DOCTOR_ID,
                            otherAppList.get(position).doctorId);

                        httpMap.put(Arguments.ACTIVITY_JUMP_UNIT_ID,
                            otherAppList.get(position).hospitalid);
                        httpMap.put(Arguments.ACTIVITY_JUMP_DETL_ID,
                            other_sch_id);
                        httpMap.put(Arguments.ACTIVITY_JUMP_ORDER_DETAIL,
                            orderDesc);
                        httpMap.put(Arguments.ACTIVITY_JUMP_GUAHAO_AMT,
                            otherAppList.get(position).orderFee);
                        httpMap.put(Arguments.MEMBER_LIST, members);
                        PotoalParcelable potoal = new PotoalParcelable(httpMap);
                        intent_1
                            .putExtra(Arguments.INTENT_TO_NEXT_PAGE, potoal);
                        intent_1.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                        startActivity(intent_1);
                    }
                    else
                    {
                        if (dlg_sch != null && dlg_sch.isShowing())
                        {
                            dlg_sch.dismiss();
                        }
                        getHospitalPayTypeTask(quick.unit_id);
                    }
                    /*
                     * dlg_member = new QuickYuyueMemberDlg(context,
                     * family.members, AppManagerActivity.this);
                     * dlg_member.show();
                     */
                }
                else
                {
                    showMsg(R.string.read_member_fail);
                }
                break;
            case HttpAsyncTask.TASK_NOTIFY_CONNECTION_FAIL:
                dismissProgressDialog();
                showSingleAlertDlg(getString(R.string.notice),
                    getString(R.string.get_family_info_err),
                    getString(R.string.close));
                break;
            }
        };
    };

    /**
     * 获取医院的支付方式
     */
    private HttpAsyncTask getHospitalPayTypeTask;

    /**
     * 根据医院的ID获取支付方式
     * 
     * @param unit_id
     */
    private void getHospitalPayTypeTask(String unit_id)
    {
        Map<String, String> parameterMap = new HashMap<String, String>();
        parameterMap.put("unit_id", unit_id);
        parameterMap.put("mobile", ConfigUtilHelper.getMobile(app));
        String changeUserInfoUrl = Utils.changeUrl(
            Arguments.SERVER_URL_GET_HOSPITAL_PAY_TYPE, parameterMap);
        getHospitalPayTypeTask = new HttpAsyncTask(HttpAsyncTask.GET,
            GlobalSetting.XML_GET_HOSPITAL_PAY_TYPE_INFO, changeUserInfoUrl,
            HttpAsyncTask.CACHE_TYPE_ACTION, false);
        showProgressDialogNew(R.string.get_pay_type_tips);
        getHospitalPayTypeTask.setUIHandler(getHospitalPayTypeTaskHandler);
        mHttpManager.execute(getHospitalPayTypeTask);
    }

    Handler getHospitalPayTypeTaskHandler = new Handler() {
        public void handleMessage(Message msg)
        {
            switch (msg.what)
            {
            case HttpAsyncTask.TASK_NOTIFY_RETURN_DATA:
                if (msg.obj != null)
                {
                    Map<String, Object> map = (Map<String, Object>) msg.obj;
                    CmccDataStatistics.onEvent(AppManagerActivity.this, 0,
                        "sure_order");
                    Intent intent_1 = new Intent(AppManagerActivity.this,
                        OrderDetailActivity.class);
                    Map<String, Object> httpMap = new HashMap<String, Object>();
                    int currentTitleSelect = R.id.left_btn;
                    httpMap.put(Arguments.ACTIVITY_JUMP_UNIT_ID, quick.unit_id);
                    httpMap.put(Arguments.ACTIVITY_JUMP_DETL_ID,
                        quick.mMastEntity.get(0).schedule_id);
                    content[0] = quick.unit_name;
                    content[1] = quick.dep_name;
                    content[2] = quick.doctor_name;
                    content[3] = scheduleList.get(position).begin_time + " - "
                        + scheduleList.get(position).end_time;
                    httpMap.put(Arguments.ACTIVITY_JUMP_ORDER_DETAIL, content);
                    // httpMap.put(Arguments.ACTIVITY_JUMP_ORDER_DETAIL,
                    // local_appointmentAdapter.content);
                    httpMap.put(Arguments.ACTIVITY_JUMP_AREA_TYPE,
                        currentTitleSelect);
                    httpMap.put(Arguments.ACTIVITY_JUMP_GUAHAO_AMT,
                        quick.mMastEntity.get(0).guahao_amt);
                    ArrayList<PayTypeModel> paytypeList = (ArrayList<PayTypeModel>) map
                        .get(Arguments.XML_PAYTYPE_LIST);
                    httpMap.put(Arguments.ACTIVITY_JUMP_PAY_TYPE_LIST,
                        paytypeList);
                    httpMap.put(Arguments.MEMBER_LIST, members);
                    PotoalParcelable potoal = new PotoalParcelable(httpMap);
                    intent_1.putExtra(Arguments.INTENT_TO_NEXT_PAGE, potoal);
                    intent_1.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(intent_1);
                }
                else
                {
                    dismissProgressDialog();
                }
                break;
            case HttpAsyncTask.TASK_NOTIFY_CONNECTION_FAIL:
                dismissProgressDialog();
                showSingleAlertDlg(getString(R.string.notice),
                    getString(R.string.read_fail), getString(R.string.close));
                break;
            }
        };
    };

    /**
     * 回调异地订单列表
     */
    @Override
    public void get_other_orders(OrderListResultModel orderListResultModel)
    {
        // TODO Auto-generated method stub
        dismissProgressDialog();
        if (orderListResultModel.resultCode.equals("000"))
        {
            if (orderListResultModel.orderList.size() > 0)
            {
                if (ConfigUtilHelper.debug)
                {
                    Log.i(TAG, "订单总数：" + orderListResultModel.totalCount);
                }
                boolean isEnd = true;
                if (currpage_other * Integer.parseInt(Arguments.pageSize) < orderListResultModel.totalCount)
                {
                    isEnd = false;
                }
                else
                {
                    isEnd = true;
                }
                otherAppList.addAll(orderListResultModel.orderList);
                if (otherAppAdapter == null)
                {
                    otherAppAdapter = new OtherOrderInfoAdapter(this,
                        otherAppList, isEnd, this, this);
                    other_list.setAdapter(otherAppAdapter);
                }
                else
                {
                    otherAppAdapter.isEnd = isEnd;
                    otherAppAdapter.notifyDataSetChanged();
                }
            }
            else
            {
                showSingleAlertDlg(getString(R.string.notice),
                    getString(R.string.other_order_no_data),
                    getString(R.string.close));
            }
        }
        else if (orderListResultModel.resultCode.equals("002"))
        {
            if (orderListResultModel.resultMsg.equals(""))
            {
                showSingleAlertDlg(getString(R.string.notice),
                    getString(R.string.read_fail), getString(R.string.close));
            }
            else
            {
                showSingleAlertDlg(getString(R.string.notice),
                    orderListResultModel.resultMsg, getString(R.string.close));
            }
        }
        else
        {
            if (orderListResultModel.resultMsg.equals(""))
            {
                showSingleAlertDlg(getString(R.string.notice),
                    getString(R.string.read_fail), getString(R.string.close));
            }
            else
            {
                showSingleAlertDlg(getString(R.string.notice),
                    orderListResultModel.resultMsg, getString(R.string.close));
            }
        }
    }

    /**
     * 加载下一页异地列表
     */
    @Override
    public void next_updateData_orders()
    {
        // TODO Auto-generated method stub
        currpage_other += 1;
        getOtherOrderList(currpage_other, ConfigUtilHelper.getMobile(app));
    }

    /**
     * 更新异地预约状态回调函数
     */
    @Override
    public void notifyUI_other(int msg, int p)
    {
        // TODO Auto-generated method stub
        position = p;
        switch (msg)
        {
        case GlobalSetting.CANCEL_ORDER:// 取消预约
            break;
        case GlobalSetting.AGIAN_ORDER:// 再次预约
            showProgressDialog();
            sendSearchSchListTask(0, otherAppList.get(p).doctorId);
            break;
        default:
            break;
        }
    }

    /**
     * 发送异地排班列表
     * 
     * @param page
     */
    private void sendSearchSchListTask(int page, String doc_id)
    {
        Map<String, String> parameterMap = new HashMap<String, String>();
        parameterMap = initArgMap(parameterMap);
        parameterMap.put("methodVit", Arguments.GetSchedules);
        parameterMap.put("doctorId", doc_id);
        parameterMap.put("page", Integer.toString(page));
        asnTask = new MyAsynaTask(mDataCallback_other,
            GlobalSetting.XML_GET_OTHER_SCH, parameterMap);
        asnTask.execute();
    }

    DataCallback_other mDataCallback_other = new DataCallback_other() {

        @Override
        public void updateData_ScheduleList(
            ScheduleResultModel mScheduleResultModel)
        {
            // TODO Auto-generated method stub
            dismissProgressDialog();
            if (mScheduleResultModel.resultCode.equals("000"))
            {
                dlg_mast = new QuickYuyueDlg(AppManagerActivity.this,
                    mScheduleResultModel.schList, AppManagerActivity.this, true);
                dlg_mast.show();
            }
        }

        @Override
        public void updateData_HospitalList(
            HospitalResultModel mHospitalResultModel)
        {
        }

        @Override
        public void updateData_DocList(DocResultModel mDocResultModel)
        {
        }

        @Override
        public void updateData_DepList(DepResultModel mDepModelResult)
        {
        }

        @Override
        public void updateData_CityList(AreaResultModel mAreaResultModel)
        {
        }

        @Override
        public void next_updateData_Schedule()
        {
        }

        @Override
        public void next_updateData_Hospital()
        {
        }

        @Override
        public void next_updateData_Doc()
        {
        }

        @Override
        public void next_updateData_Dep()
        {
        }

        @Override
        public void next_updateData()
        {
        }

        @Override
        public void get_hospital_info(HospitalInfoModel hospitalInfoModel)
        {
        }

        @Override
        public void get_doc_info(DocInfoModel docInfoModel)
        {
        }

        @Override
        public void callback_hospital_info(int p)
        {
        }

        @Override
        public void callback_doc_info(int p)
        {
        }
    };

    private String other_sch_id;
    private String other_content;

    /**
     * 获取异地班次信息回调函数
     */
    @Override
    public void notifyUI_other(String sch_id, String content)
    {
        this.other_sch_id = sch_id;
        this.other_content = content;
        isOther = true;
        getFamily();
    }

    @Override
    public void notifyUI_member(MemberModel member)
    {
        if (isOther)
        {
            String order_free_other = "0";
            String[] orderDescs = otherAppList.get(position).orderDesc
                .split(" ");
            String orderDesc = "";
            for (int i = 0; i < orderDescs.length; i++)
            {
                if (i < 5)
                {
                    if (orderDesc.equals(""))
                    {
                        orderDesc = orderDescs[i];
                    }
                    else
                    {
                        orderDesc = orderDesc + " " + orderDescs[i];
                    }

                }
            }
            orderDesc = orderDesc + " " + other_content;
            // String[] desc = orderDesc.split(" ");
            Intent intent_1 = new Intent(AppManagerActivity.this,
                OrderDetailActivity.class);
            Map<String, Object> httpMap = new HashMap<String, Object>();
            httpMap.put(Arguments.ACTIVITY_JUMP_AREA_TYPE, R.id.right_btn);

            httpMap.put(Arguments.ACTIVITY_JUMP_CHOICE_DOCTOR_TYPE,
                otherAppList.get(position).reservationType);
            httpMap.put(Arguments.ACTIVITY_JUMP_DEP_ID,
                otherAppList.get(position).deptId);
            httpMap.put(Arguments.ACTIVITY_JUMP_DOCTOR_ID,
                otherAppList.get(position).doctorId);

            httpMap.put(Arguments.ACTIVITY_JUMP_UNIT_ID,
                otherAppList.get(position).hospitalid);
            httpMap.put(Arguments.ACTIVITY_JUMP_DETL_ID, other_sch_id);
            httpMap.put(Arguments.ACTIVITY_JUMP_ORDER_DETAIL, orderDesc);
            httpMap.put(Arguments.ACTIVITY_JUMP_GUAHAO_AMT,
                otherAppList.get(position).orderFee);
            httpMap.put(Arguments.MEMBER_MODEL, member);
            PotoalParcelable potoal = new PotoalParcelable(httpMap);
            intent_1.putExtra(Arguments.INTENT_TO_NEXT_PAGE, potoal);
            intent_1.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(intent_1);
        }
        else
        {
            getHospitalPayTypeTask(quick.unit_id);
        }
        dlg_member.dismiss();
    }

}